home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Other Stuff
/
Other Stuff ’97
/
PowerOS Development
/
basic kernel source
/
debug_console.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-26
|
4KB
|
172 lines
/*
debug_console.c
a source file for PowerOS
copyright 1996-1997 by Ben Martz
all rights reserved world wide
ANY AND ALL MODIFICATIONS TO THIS SOURCE MUST CREDIT THE ORIGINAL
AUTHOR, BEN MARTZ (benmartz@ic.net), AND MUST BE GIVEN TO THE AUTHOR
FOR INTEGRATION INTO THE MAIN PowerOS SOURCE TREE. THANK YOU FOR YOUR
COOPERATION!
*/
#include "poweros_types.h"
#include "debug_video.h"
#include "debug_console.h"
#include "debug_console_font.h"
#define KCHAR_WIDTH 6 /* these include and v spacing */
#define KCHAR_HEIGHT 10
ConsolePrivateData consolePrivate;
void cinit(void) {
int i;
consolePrivate.width = vgetwidth();
consolePrivate.height = vgetheight();
consolePrivate.cols = consolePrivate.width / KCHAR_WIDTH;
consolePrivate.rows = consolePrivate.height / KCHAR_HEIGHT;
if(vgetdepth() > 8) {
consolePrivate.forecolor = 0xFFFFFFFF;
consolePrivate.backcolor = 0L;
} else {
consolePrivate.forecolor = 0L;
consolePrivate.backcolor = 0xFFFFFFFF;
}
cgotoxy(1,1);
cputchar('C');cputchar('O');cputchar('N');cputchar('S');cputchar('O');cputchar('L');cputchar('E');cputchar('\n');
/* some debugging info */
dprintf("debug_console - %d bit %dx%d video -> %dx%d console\n",vgetdepth(),vgetwidth(),
vgetheight(),consolePrivate.cols,consolePrivate.rows);
for(i = 1; i <= consolePrivate.cols; i++) {
cputchar('*');
}
cputchar('\n');
}
void cputchar(u_char c) {
char count;
int offh = 0, offv = 0;
long ec, ec2;
switch(c) {
case '\t':
ctab();
break;
case '\n':
cnewline();
break;
default:
c *= 2;
ec = KERNEL_FONT[c];
ec2 = KERNEL_FONT[c + 1];
for(count = 0; count < 32; count++) {
if(ec & (1 << count)) {
cputcharpixel(offh, offv, consolePrivate.forecolor);
} else {
cputcharpixel(offh, offv, consolePrivate.backcolor);
}
if(++offh > KCHAR_WIDTH - 1) {
offh = 0;
offv++;
}
}
for(count = 32; count < 60; count++) {
if(ec2 & (1 << (count - 32))) {
cputcharpixel(offh, offv, consolePrivate.forecolor);
} else {
cputcharpixel(offh, offv, consolePrivate.backcolor);
}
if(++offh > KCHAR_WIDTH - 1) {
offh = 0;
offv++;
}
}
cgotoxy(consolePrivate.colpos + 1, consolePrivate.rowpos);
break;
}
}
void cputcharpixel(int offsetH, int offsetV, u_long value) {
vputpixel(consolePrivate.xpos + offsetH, consolePrivate.ypos + offsetV, value);
}
void cgotoxy(int x, int y) {
int tmpx, tmpy;
tmpx = x;
tmpy = y;
if(tmpx < 1) tmpx = 1;
if(tmpy < 1) tmpy = 1;
if(tmpx > consolePrivate.cols) {
tmpx = 1;
tmpy++;
}
if(tmpy > consolePrivate.rows) {
tmpx = 1;
tmpy = consolePrivate.rows;
vscrollup(KCHAR_HEIGHT);
}
consolePrivate.colpos = tmpx;
consolePrivate.rowpos = tmpy;
consolePrivate.xpos = (tmpx - 1) * KCHAR_WIDTH;
consolePrivate.ypos = (tmpy - 1) * KCHAR_HEIGHT;
}
long cgetforecolor(void) {
return consolePrivate.forecolor;
}
void csetforecolor(long color) {
consolePrivate.forecolor = color;
}
long cgetbackcolor(void) {
return consolePrivate.backcolor;
}
void csetbackcolor(long color) {
consolePrivate.backcolor = color;
}
int cgetx(void) {
return consolePrivate.colpos;
}
int cgety(void) {
return consolePrivate.rowpos;
}
int cgetxmax(void) {
return consolePrivate.cols;
}
int cgetymax(void) {
return consolePrivate.rows;
}
void ctab(void) {
cgotoxy(consolePrivate.colpos + 4, consolePrivate.rowpos);
}
void cnewline(void) {
cgotoxy(1, consolePrivate.rowpos + 1);
}